<template>
  <Form class="login-form-box" ref="loginForm" :model="form" :rules="rules" @keydown.enter.native="handleSubmit">
    <FormItem prop="userName">
      <Input v-model="form.username" placeholder="请输入登录账号">
      <span slot="prepend">
        <Icon :size="16" type="ios-person"></Icon>
      </span>
      </Input>
    </FormItem>
    <FormItem prop="password">
      <Input type="password" v-model="form.pwd" placeholder="请输入登录密码">
      <span slot="prepend">
        <Icon :size="14" type="md-lock"></Icon>
      </span>
      </Input>
    </FormItem>
    <div style="position: relative;top:-10px;">
      <!-- <Checkbox v-model="form.remberPwd">记住密码</Checkbox> -->
    </div>
    <FormItem>
      <Button @click="handleSubmit" type="warning" long style="margin-top:40px;">登录</Button>
    </FormItem>
  </Form>
</template>
<script>
  export default {
    name: 'LoginForm',
    props: {
      userNameRules: {
        type: Array,
        default: () => {
          return [{
            required: true,
            message: '账号不能为空',
            trigger: 'blur'
          }]
        }
      },
      passwordRules: {
        type: Array,
        default: () => {
          return [{
            required: true,
            message: '密码不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    data() {
      return {
        form: {
          userName: ' ',
          password: '',
          remberPwd: false
        }
      }
    },
    computed: {
      rules() {
        return {
          username: this.userNameRules,
          pwd: this.passwordRules
        }
      }
    },
    methods: {
      handleSubmit() {
        this.$refs.loginForm.validate((valid) => {
          if (valid) {
            this.$emit('on-success-valid', {
              username: this.form.username,
              pwd: this.form.pwd
            })
          }
        })
      }
    }
  }
</script>
